from typing import Optional
import typing

import PySide6.QtCore
import PySide6.QtWidgets
from PySide6.QtCore import Qt, Signal
from PySide6.QtGui import QIcon, QTabletEvent
from PySide6.QtWidgets import QTabWidget, QWidget

from .Ui_DelWidget import Ui_DelWidget


class DelWidget(QWidget):
    '''
    description:
        一个窗体，左边是Label，右边是PushButton
        可以用于一些Item控件的便利增删
    signals:
        SigPushButton(QWidget):
            - QWidget 本窗体对象
    args:
        label_text: 'str' 左边label要设置的文字
        button_text: 'str' 右边button上要设置的文字
        button_icon: 'QIcon' 右边button上要设置的Icon
        parent 'QWidget' 父窗体 默认是None
        f ’WindowFlags’ 窗体标志，默认为Qt.Widget
    return:
        None
    '''
    SigPushButtonClicked = Signal(QWidget)     # 当本窗体的按钮按下后发出
    def __init__(
        self, 
        label_text: 'str' = '',
        button_text: 'str' = 'D',
        button_icon: 'QIcon' = QIcon(),
        container = None,
        parent: Optional[PySide6.QtWidgets.QWidget] = None, 
        f: PySide6.QtCore.Qt.WindowFlags = Qt.Widget) -> None:
        ###########################################
        super().__init__(parent=parent, f=f)
        self._ui = Ui_DelWidget()
        self._ui.setupUi(self)
        self._ui.labelPath.setText(label_text)
        self._ui.pushButtonDel.setText(button_text)
        self._container = container
        if (not button_icon.isNull()):
            self._ui.pushButtonDel.setIcon(button_icon)
        # 设置信号槽 ===============================
        self._ui.pushButtonDel.clicked.connect(self._SlotPushbuttonDelClicked)
        # ========================================
        
    
    def _SlotPushbuttonDelClicked(self) -> None:
        '''
        funtion:
            当按下 Del 按钮后做什么事情:
                - 发送按钮按下的信号
        args:
            None
        return:
            None
        '''
        self.SigPushButtonClicked.emit(self)
    
    def GetText(self) -> 'str':
        '''
        function:
            获取本窗体 Label 中的 Text
        agrs:
            None
        return:
            None
        '''
        return self._ui.labelPath.text()

    def Container(self) -> typing.Any:
        '''
        funtion:
            获取本窗体的 Container 对象，供父对象来处理操作本窗体
        args:
            None
        return:
            typing.Any 任何，需要调用者来判断类型
        '''
        return self._container
    
